package com.college.heyuhua.dao;

import com.college.heyuhua.entity.UserInfo;
import com.college.heyuhua.model.BBSInfo;
import com.college.heyuhua.model.FileModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by 赵东坡 on 2019/1/27.
 * Time:18:45
 * 宇宙无敌赵牛逼，祈求永无bug
 */
@Mapper
@Component
public interface FileMapper {

    @Select("<script>" +
            "select * " +
            "from shardinfo s " +
            "</script>")
    public List<FileModel> getFileModelList();

    @Select("<script>" +
            " SELECT MAX(fid) FROM shardinfo " +
            "</script>")
    int getFileModeMax();

    @Select("<script>" +
            " SELECT MIN(fid) FROM shardinfo " +
            "</script>")
    int getFileModeMin();

    @Select("<script>" +
            "select * " +
            "from usersinfo u " +
            "where u.uid = #{uid} " +
            "</script>")
    UserInfo getUserInfo(@Param("uid") long uid);



    @Select("<script>" +
            "select * " +
            "from bbsinfo b " +
            "where b.nid = #{fid} and b.style = #{filebbs} " +
            "order by b.bbsdate desc " +
            "</script>")
    List<BBSInfo> getBBSListForFile(@Param("fid") int fid, @Param("filebbs") String filebbs);



    @Insert("<script>" +
            "insert into bbsinfo(uid,bbscontent,style,nid) " +
            "values(#{uid},#{bbscontent},#{filebbs},#{fid}) " +
            "</script>")
    boolean submitbbs(@Param("bbscontent") String bbscontent,@Param("fid") String fid,@Param("uid") String uid,@Param("filebbs") String filebbs);



    @Insert("<script>" +
            "insert into shardinfo(filename,fileshort,filetype,uid,fileurl) " +
            "values(#{filemodel.filename},#{filemodel.fileshort},#{filemodel.filetype},#{filemodel.uid},#{filemodel.fileurl}) " +
            "</script>")
    boolean insertfileshard(@Param("filemodel") FileModel shardinfo);


    @Select("<script>" +
            "select * " +
            "from shardinfo s " +
            "where s.filename like #{filename} " +
            "</script>")
    FileModel searchFile(@Param("filename") String filename);
}
